package tk.mybatis.springboot.service;

import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.springboot.mapper.TUserMapper;
import tk.mybatis.springboot.model.TUser;

import java.util.List;

/**
 * Created by NightDream on 2017/9/11.
 */
@Service
public class UserService {

    @Autowired
    private TUserMapper tUserMapper;

    public void save(TUser sysUser) {
        if (sysUser.getId() != null) {
            tUserMapper.updateByPrimaryKey(sysUser);
        } else {
            tUserMapper.insert(sysUser);
        }
    }

    public void deleteById(Integer id) {
        tUserMapper.deleteByPrimaryKey(id);
    }

    public List<TUser> getAll(TUser sysUser) {
        if (sysUser.getPage() != null && sysUser.getRows() != null) {
            PageHelper.startPage(sysUser.getPage(), sysUser.getRows());
        }
        return tUserMapper.selectAll();
    }

    public TUser getUser(TUser TUser) {
        TUser user = tUserMapper.selectOne(TUser);
        return user;
    }
}
